package com.jxd.controller;

import com.jxd.model.TravelInfo;
import com.jxd.service.ITicketInfoService;
import com.jxd.service.ITravelInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/travelInfo")
public class TravelInfoController {

    @Autowired
    private ITravelInfoService travelInfoService;

    @PostMapping("/travelInfoList")
    public Map<String, Object> travelInfoList(@RequestBody Map<String, String> map) {
        Map<String, Object> map1 = travelInfoService.getAllTravelInfoList(map);
        return map1;
    }

    @RequestMapping("/addTravelInfo")
    public Map<String, Object> addTravelInfo(@RequestBody TravelInfo travelInfo) {
        HashMap<String, Object> res = new HashMap<>();
        boolean flag = travelInfoService.save(travelInfo);
        if (flag) {
            res.put("tid", travelInfo.getId());
            res.put("code", "200");
            return res;
        } else {
            res.put("code", "500");
            return res;
        }
    }

    @RequestMapping("/updateTravelInfo")
    public String updateTravelInfo(@RequestBody TravelInfo travelInfo) {
        return travelInfoService.updateById(travelInfo) ? "success" : "error";
    }

    @RequestMapping("/delTravelInfo")
    public String delTravelInfo(@RequestBody List<Integer> ids) {
        return travelInfoService.removeByIds(ids) ? "success" : "error";
    }

    @RequestMapping("/getTravelInfo/{id}")
    public TravelInfo getTravelInfo(@PathVariable int id) {
        return travelInfoService.getById(id);
    }
}
